package com.jack.thinking.thread.core._1;

/**
 * yield method
 * @author wangbingwu
 *
 */
public class YieldGiveUpCpu {
	public static void main(String[] args) {
		MyThreadTime tt = new MyThreadTime();
		Thread yield1 = new Thread(tt);
		yield1.setPriority(5);
		yield1.start();
		
		Thread yield2 = new Thread(tt);
		yield2.start();
		yield1.setPriority(9);
	}
}

class MyThreadTime extends Thread{
	
	@Override
	public void run() {
		long begin = System.currentTimeMillis();
		int count = 0;
		for (int i = 0; i < 1000000; i++) {
			Thread.yield();
			count = count + i + 1;
			System.out.println(Thread.currentThread().getName() + " num: " + count);
		}
		long end = System.currentTimeMillis();
		System.out.println(end - begin);
	}
}